package com.clf.task.job;

import com.clf.task.annotation.ElasticScheduler;
import com.clf.task.handler.SpringUtil;
import com.clf.task.job.service.StockSimpleService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import org.springframework.stereotype.Component;

@Component
@ElasticScheduler(cron = "0/5 * * * * ?", shardingTotalCount = 1, name = "测试注解", shardingItemParameters = "0=0,1=0,2=1,3=1")
public class StockSimpleJob implements SimpleJob {


    @Override
    public void execute(ShardingContext shardingContext) {
        System.out.println(String.format("------Thread ID: %s, 任务分片数: %s, " +
                        "当前分片项: %s.当前参数: %s," +
                        "当前任务名称: %s.当前任务参数: %s"
                ,
                Thread.currentThread().getId(),
                shardingContext.getShardingTotalCount(),
                shardingContext.getShardingItem(),
                shardingContext.getShardingParameter(),
                shardingContext.getJobName(),
                shardingContext.getJobParameter()

        ));

        StockSimpleService bean = SpringUtil.getBean(StockSimpleService.class);

        bean.test();
    }

}
